package com.onlineclass.school.controller;

import com.onlineclass.beas.Course;
import com.onlineclass.beas.ResultObject;
import com.onlineclass.beas.School;
import com.onlineclass.beas.UserInfo;
import com.onlineclass.school.service.ISchoolNameService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/School")
@Slf4j
public class SchoolController {

    @Autowired
    ISchoolNameService iSchoolNameService;


    @RequestMapping("/getSchool")
    public ResultObject getSchoolName(){
        ResultObject o = new ResultObject();
        List<School> school = iSchoolNameService.getSchoolNmae();
        if (school == null) {
            o.setStatus(404);
            o.setInfo("查寻失败");

            return o;
        } else {
            o.setStatus(1);
            o.setInfo("查寻成功");
            o.setData(school);
            return o;
        }
    }

    @RequestMapping("/schoolinfo")
    public ResultObject getSchoolInfo(int id){
        ResultObject o = new ResultObject();
        List<UserInfo> userInfos = iSchoolNameService.getSchoolInfo(id);
        if (userInfos == null) {
            o.setStatus(404);
            o.setInfo("查寻失败");

            return o;
        } else {
            o.setStatus(1);
            o.setInfo("查寻成功");
            o.setData(userInfos);
            return o;
        }
    }

}
